package com.xhl.lk.auth2.modules.admin.demo;

import redis.clients.jedis.Jedis;

public class BloomFilterExample {

    private Jedis jedis;

    public BloomFilterExample() {
        jedis = new Jedis("192.168.245.181",6379);
        jedis.auth("508816");
    }

    public void add(String key, String value) {
        jedis.setbit(key, Long.parseLong(value), true);
    }

    public boolean contains(String key, String value) {
        return jedis.getbit(key, Long.parseLong(value));
    }

    public static void main(String[] args) {
        BloomFilterExample example = new BloomFilterExample();
        example.add("bloom-filter", "1");
        example.add("bloom-filter", "2");

        System.out.println(example.contains("bloom-filter", "1")); // true
        System.out.println(example.contains("bloom-filter", "2")); // true
        System.out.println(example.contains("bloom-filter", "3")); // false
    }
}
